package calculator;

import java.util.LinkedList;

public class Calculator {

	public double divide(String s1, String s2) {

		int n1 = Integer.parseInt(s1);
		int n2 = Integer.parseInt(s2);
		int br = 0;
		int rest = 0;
		
		String result = "";
		
		while (n1 != 0) {	
			if(n1<n2){
				rest = n1;
				break;
			}
			n1 = n1-n2;
			br++;
		}
		
		result = br+".";
		rest = rest*10;
		
		int brrest = 0;
		int b = 10;
		
		while (rest != 0 && b!=0) {
			if (rest < n2) {
				rest = rest * 10;
				result = result + brrest;
				brrest = 0;
				b--;
			}
			rest = rest - n2;
			brrest++;
		}
		
		result = result+brrest;
		
		double resultDouble = Double.parseDouble(result);
		
		return resultDouble;
	}
	
	public int multiply(String s1, String s2){
		
		int n1 = Integer.parseInt(s1);
		int n2 = Integer.parseInt(s2);
		int sum = 0;
		
		for(int i=0; i<n2;i++){
			sum = sum+n1;
		}
		
		return sum;
	}
	
	public int addition(String s1, String s2){
		
		int n1 = Integer.parseInt(s1);
		int n2 = Integer.parseInt(s2);
		
		int sum = 0;
		sum = n1 + n2;
		
		return sum;
	}
	
	public int subtraction(String s1, String s2){
	
		int n1 = Integer.parseInt(s1);
		int n2 = Integer.parseInt(s2);
		String result = "";
		int sum = 0;
		
		if(n1>n2){
			sum = n1 - n2;
			result = result+sum;
		}
		if(n1<n2){
			sum = n2-n1;
			result = "-"+sum;
		}
		
		int resultSub = Integer.parseInt(result);
		return resultSub;
	}
}
